/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaNovoFornecedor.java
 *
 * Created on 09/11/2011, 23:28:41
 */
package gui.pessoa;

import banco.pessoa.BancoFornecedor;
import excecoes.estoque.DinheiroNegativoException;
import excecoes.pessoa.CpfCnpjExistenteException;
import excecoes.pessoa.CpfCnpjInvalidoException;
import excecoes.pessoa.LocalizacaoInvalidaException;
import excecoes.pessoa.NomeFantasiaNuloException;
import excecoes.pessoa.NomeInvalidoException;
import gui.estoque.JFrameTableEstoque;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import smartMarket.pessoa.Fornecedor;

/**
 *
 * @author dyego
 */
public class JFrameNovoFornecedor extends javax.swing.JFrame {

    // Atributos
    private Integer linhaSelecionada;
    private String acao;

    // Construtor
    public JFrameNovoFornecedor() {
        initFornecedor();
        linhaSelecionada = null;
        this.acao = "cadastrar";
    }

    public JFrameNovoFornecedor(int linha, String cnpj) {
        initFornecedor(cnpj);
        linhaSelecionada = linha;
        this.acao = "alterar";
    }

    // Métodos 
    private Fornecedor getTextField() throws NomeFantasiaNuloException, CpfCnpjInvalidoException, CpfCnpjExistenteException {

        Fornecedor novoFornecedor = new Fornecedor();

        try {

            novoFornecedor.setCodigo(Integer.parseInt(jTextFieldCodigo.getText()));
            novoFornecedor.setBairro(jTextFieldBairro.getText());
            novoFornecedor.setCelular(jFormattedTextFieldCelular.getText());
            novoFornecedor.setCidade(jTextFieldCidade.getText());
            novoFornecedor.setCPF_CNPJ(jFormattedTextFieldCNPJ.getText(), true);
            novoFornecedor.setEmail(jTextFieldEmail.getText());
            novoFornecedor.setNome(jTextFieldRazaoSocial.getText());
            novoFornecedor.setNomeFantasia(jTextFieldNomeFantasia.getText());
            novoFornecedor.setNumero(jTextFieldNumero.getText());
            novoFornecedor.setRua(jTextFieldEndereco.getText());
            novoFornecedor.setTelefone(jFormattedTextFieldTelefone.getText());
            novoFornecedor.setEstado(jComboBoxEstado.getSelectedIndex());
            novoFornecedor.setLimiteDeCredito(Float.parseFloat(jFormattedTextFieldLimite.getText().replace(".", "").replace(",", ".")));

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        } catch (DinheiroNegativoException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        } catch (CpfCnpjExistenteException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        } catch (LocalizacaoInvalidaException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        } catch (CpfCnpjInvalidoException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        } catch (NomeInvalidoException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }

        return novoFornecedor;

    }

    private void cadastrar() {

        try {

            Fornecedor novoFornecedor = this.getTextField();
            BancoFornecedor bf = new BancoFornecedor();
            bf.novo(novoFornecedor);

            Object[] addTable = {novoFornecedor.getCodigo(),
                novoFornecedor.getCPF_CNPJ(),
                novoFornecedor.getNome()};

            JFrameTableEstoque.model.addRow(addTable);

        } catch (CpfCnpjInvalidoException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CpfCnpjExistenteException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NomeFantasiaNuloException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException e) {
        }
    }

    private void alterar() {
        try {

            Fornecedor novoFornecedor = this.getTextField();
            BancoFornecedor bf = new BancoFornecedor();
            try {
                bf.alterar(novoFornecedor);

                Object[] addTable = {novoFornecedor.getCodigo(),
                    novoFornecedor.getCPF_CNPJ(),
                    novoFornecedor.getNome()};

                JFrameTableCadastroCliente.model.removeRow(this.linhaSelecionada);
                JFrameTableCadastroCliente.model.insertRow(this.linhaSelecionada, addTable);

            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, e.getMessage());
            }



        } catch (CpfCnpjInvalidoException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE,null, ex);
        } catch (CpfCnpjExistenteException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NomeFantasiaNuloException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        }



    }

    private void initFornecedor() {
        initComponents();

        try {

            BancoFornecedor bf = new BancoFornecedor();
            jTextFieldCodigo.setText("" + (bf.ultimoFornecedor() + 1));

        } catch (NullPointerException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        } catch (SQLException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        } catch (NomeInvalidoException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        } catch (CpfCnpjInvalidoException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
    }

    private void initFornecedor(String cnpj){
        initComponents();

        try {

            BancoFornecedor bf = new BancoFornecedor();
            Fornecedor novoFornecedor;

            novoFornecedor = bf.buscar(cnpj);
            jComboBoxEstado.setSelectedIndex(novoFornecedor.getEstado());
            jFormattedTextFieldCNPJ.setText(novoFornecedor.getCPF_CNPJ());
            jFormattedTextFieldCelular.setText(novoFornecedor.getCelular());
            jFormattedTextFieldLimite.setText("" + novoFornecedor.getLimiteDeCredito());
            jFormattedTextFieldTelefone.setText(novoFornecedor.getTelefone());

            jTextFieldBairro.setText(novoFornecedor.getBairro());
            jTextFieldCidade.setText(novoFornecedor.getCidade());
            jTextFieldCodigo.setText("" + novoFornecedor.getCodigo());
            jTextFieldEmail.setText(novoFornecedor.getEmail());
            jTextFieldEndereco.setText(novoFornecedor.getRua());
            jTextFieldNomeFantasia.setText(novoFornecedor.getNomeFantasia());
            jTextFieldNumero.setText(novoFornecedor.getNumero());
            jTextFieldRazaoSocial.setText(novoFornecedor.getNome());


        } catch (DinheiroNegativoException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CpfCnpjExistenteException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (LocalizacaoInvalidaException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NomeFantasiaNuloException ex) {
            Logger.getLogger(JFrameNovoFornecedor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NullPointerException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        } catch (SQLException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        } catch (NomeInvalidoException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        } catch (CpfCnpjInvalidoException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelInformacoesAdicionais = new javax.swing.JPanel();
        jLabelTelefone = new javax.swing.JLabel();
        jLabelEmail = new javax.swing.JLabel();
        jLabelCelular = new javax.swing.JLabel();
        jTextFieldEmail = new javax.swing.JTextField();
        jFormattedTextFieldTelefone = new javax.swing.JFormattedTextField();
        jFormattedTextFieldCelular = new javax.swing.JFormattedTextField();
        jFormattedTextFieldLimite = new javax.swing.JFormattedTextField();
        jLabelLimite = new javax.swing.JLabel();
        jPanelDadosFornecedor = new javax.swing.JPanel();
        jLabelCodigo = new javax.swing.JLabel();
        jLabelRazaoSocial = new javax.swing.JLabel();
        jLabelCNPJ = new javax.swing.JLabel();
        jTextFieldCodigo = new javax.swing.JTextField();
        jFormattedTextFieldCNPJ = new javax.swing.JFormattedTextField();
        jLabelNomeFantasia = new javax.swing.JLabel();
        jTextFieldNomeFantasia = new javax.swing.JTextField();
        jTextFieldRazaoSocial = new javax.swing.JTextField();
        jPanelLocalizacao = new javax.swing.JPanel();
        jLabelEstado = new javax.swing.JLabel();
        jTextFieldEndereco = new javax.swing.JTextField();
        jLabelCidade = new javax.swing.JLabel();
        jLabelEndereco = new javax.swing.JLabel();
        jTextFieldCidade = new javax.swing.JTextField();
        jLabelNumero = new javax.swing.JLabel();
        jTextFieldNumero = new javax.swing.JTextField();
        jLabelBairro = new javax.swing.JLabel();
        jTextFieldBairro = new javax.swing.JTextField();
        jComboBoxEstado = new javax.swing.JComboBox();
        jButtonCadastrar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanelInformacoesAdicionais.setBorder(javax.swing.BorderFactory.createTitledBorder("Informações adicionais"));
        jPanelInformacoesAdicionais.setToolTipText("");
        jPanelInformacoesAdicionais.setName(""); // NOI18N

        jLabelTelefone.setText("Telefone: ");

        jLabelEmail.setText("e-mail: ");

        jLabelCelular.setText("Celular: ");

        try {
            jFormattedTextFieldTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            jFormattedTextFieldCelular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jFormattedTextFieldLimite.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jFormattedTextFieldLimite.setText("0,00");
        jFormattedTextFieldLimite.setToolTipText("");

        jLabelLimite.setText("Crédito: ");

        javax.swing.GroupLayout jPanelInformacoesAdicionaisLayout = new javax.swing.GroupLayout(jPanelInformacoesAdicionais);
        jPanelInformacoesAdicionais.setLayout(jPanelInformacoesAdicionaisLayout);
        jPanelInformacoesAdicionaisLayout.setHorizontalGroup(
            jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelTelefone)
                    .addComponent(jLabelEmail))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jFormattedTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelCelular)
                    .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jLabelLimite)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jFormattedTextFieldLimite, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextFieldCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        jPanelInformacoesAdicionaisLayout.setVerticalGroup(
            jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                        .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelCelular)
                            .addComponent(jFormattedTextFieldCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelLimite)
                            .addComponent(jFormattedTextFieldLimite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                        .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelTelefone)
                            .addComponent(jFormattedTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelEmail)
                            .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelDadosFornecedor.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados do Fornecedor"));
        jPanelDadosFornecedor.setToolTipText("");
        jPanelDadosFornecedor.setName(""); // NOI18N

        jLabelCodigo.setText("Código: ");

        jLabelRazaoSocial.setText("Razão Social: ");

        jLabelCNPJ.setText("CNPJ: ");

        jTextFieldCodigo.setEditable(false);
        jTextFieldCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldCodigoKeyPressed(evt);
            }
        });

        try {
            jFormattedTextFieldCNPJ.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabelNomeFantasia.setText("Nome Fantasia: ");

        jTextFieldNomeFantasia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNomeFantasiaActionPerformed(evt);
            }
        });
        jTextFieldNomeFantasia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldNomeFantasiaKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldNomeFantasiaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldNomeFantasiaKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanelDadosFornecedorLayout = new javax.swing.GroupLayout(jPanelDadosFornecedor);
        jPanelDadosFornecedor.setLayout(jPanelDadosFornecedorLayout);
        jPanelDadosFornecedorLayout.setHorizontalGroup(
            jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDadosFornecedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelRazaoSocial)
                    .addComponent(jLabelNomeFantasia)
                    .addComponent(jLabelCodigo))
                .addGap(18, 18, 18)
                .addGroup(jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDadosFornecedorLayout.createSequentialGroup()
                        .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelCNPJ)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jFormattedTextFieldCNPJ, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))
                    .addComponent(jTextFieldRazaoSocial, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
                    .addComponent(jTextFieldNomeFantasia, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelDadosFornecedorLayout.setVerticalGroup(
            jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDadosFornecedorLayout.createSequentialGroup()
                .addGroup(jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextFieldCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCNPJ)
                    .addComponent(jLabelCodigo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelRazaoSocial)
                    .addComponent(jTextFieldRazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldNomeFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNomeFantasia))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelLocalizacao.setBorder(javax.swing.BorderFactory.createTitledBorder("Localização"));

        jLabelEstado.setText("Estado: ");

        jTextFieldEndereco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldEnderecoActionPerformed(evt);
            }
        });

        jLabelCidade.setText("Cidade: ");

        jLabelEndereco.setText("Endereço: ");

        jLabelNumero.setText("Numero: ");

        jLabelBairro.setText("Bairro: ");

        jComboBoxEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Acre", "Alagoas", "Amapá", "Amazonas", "Bahia", "Ceará", "Distrito Federal", "Espírito Santo", "Goiás", "Maranhão", "Mato Grosso", "Mato Grosso do Sul", "Minas Gerais", "Pará", "Paraíba", "Paraná", "Pernambuco", "Piauí", "Roraima", "Rondônia", "Rio de Janeiro", "Rio Grande do Norte", "Rio Grande do Sul", "Santa Catarina", "São Paulo", "Sergipe", "Tocantins" }));
        jComboBoxEstado.setToolTipText("");

        javax.swing.GroupLayout jPanelLocalizacaoLayout = new javax.swing.GroupLayout(jPanelLocalizacao);
        jPanelLocalizacao.setLayout(jPanelLocalizacaoLayout);
        jPanelLocalizacaoLayout.setHorizontalGroup(
            jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLocalizacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelBairro)
                    .addComponent(jLabelCidade)
                    .addComponent(jLabelEndereco))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldBairro)
                    .addComponent(jTextFieldEndereco)
                    .addComponent(jTextFieldCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelNumero)
                    .addComponent(jLabelEstado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBoxEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        jPanelLocalizacaoLayout.setVerticalGroup(
            jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLocalizacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelCidade))
                    .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboBoxEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelEstado)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEndereco)
                    .addComponent(jLabelNumero)
                    .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelBairro)
                    .addComponent(jTextFieldBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonCadastrar.setText("Cadastrar");
        jButtonCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCadastrarActionPerformed(evt);
            }
        });

        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonCancelarMousePressed(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonCancelarMouseClicked(evt);
            }
        });
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(29, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonCancelar)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonCadastrar))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jPanelInformacoesAdicionais, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanelDadosFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanelLocalizacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(26, 26, 26))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jPanelDadosFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanelLocalizacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanelInformacoesAdicionais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCadastrar)
                    .addComponent(jButtonCancelar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jTextFieldCodigoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCodigoKeyPressed
}//GEN-LAST:event_jTextFieldCodigoKeyPressed

private void jTextFieldEnderecoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldEnderecoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextFieldEnderecoActionPerformed

private void jButtonCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCadastrarActionPerformed
    if (this.acao.equals("cadastrar")) {
        this.cadastrar();
    } else {
        this.alterar();
    }

    this.setVisible(false);
}//GEN-LAST:event_jButtonCadastrarActionPerformed

private void jButtonCancelarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonCancelarMousePressed
    this.setVisible(false);
}//GEN-LAST:event_jButtonCancelarMousePressed

private void jButtonCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonCancelarMouseClicked
}//GEN-LAST:event_jButtonCancelarMouseClicked

private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButtonCancelarActionPerformed

private void jTextFieldNomeFantasiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNomeFantasiaActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextFieldNomeFantasiaActionPerformed

private void jTextFieldNomeFantasiaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNomeFantasiaKeyTyped
// TODO add your handling code here:
}//GEN-LAST:event_jTextFieldNomeFantasiaKeyTyped

private void jTextFieldNomeFantasiaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNomeFantasiaKeyPressed
// TODO add your handling code here:
}//GEN-LAST:event_jTextFieldNomeFantasiaKeyPressed

private void jTextFieldNomeFantasiaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNomeFantasiaKeyReleased
// TODO add your handling code here:
}//GEN-LAST:event_jTextFieldNomeFantasiaKeyReleased


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCadastrar;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JComboBox jComboBoxEstado;
    private javax.swing.JFormattedTextField jFormattedTextFieldCNPJ;
    private javax.swing.JFormattedTextField jFormattedTextFieldCelular;
    private javax.swing.JFormattedTextField jFormattedTextFieldLimite;
    private javax.swing.JFormattedTextField jFormattedTextFieldTelefone;
    private javax.swing.JLabel jLabelBairro;
    private javax.swing.JLabel jLabelCNPJ;
    private javax.swing.JLabel jLabelCelular;
    private javax.swing.JLabel jLabelCidade;
    private javax.swing.JLabel jLabelCodigo;
    private javax.swing.JLabel jLabelEmail;
    private javax.swing.JLabel jLabelEndereco;
    private javax.swing.JLabel jLabelEstado;
    private javax.swing.JLabel jLabelLimite;
    private javax.swing.JLabel jLabelNomeFantasia;
    private javax.swing.JLabel jLabelNumero;
    private javax.swing.JLabel jLabelRazaoSocial;
    private javax.swing.JLabel jLabelTelefone;
    private javax.swing.JPanel jPanelDadosFornecedor;
    private javax.swing.JPanel jPanelInformacoesAdicionais;
    private javax.swing.JPanel jPanelLocalizacao;
    private javax.swing.JTextField jTextFieldBairro;
    private javax.swing.JTextField jTextFieldCidade;
    private javax.swing.JTextField jTextFieldCodigo;
    private javax.swing.JTextField jTextFieldEmail;
    private javax.swing.JTextField jTextFieldEndereco;
    private javax.swing.JTextField jTextFieldNomeFantasia;
    private javax.swing.JTextField jTextFieldNumero;
    private javax.swing.JTextField jTextFieldRazaoSocial;
    // End of variables declaration//GEN-END:variables
}
